#include "TabelPMK.h"

int main() {
	TabelMhs T = CreateEmptyTabelMhs();
	printf("Tabel Mahasiswa\n");
	PrintTabelMhs(T); puts("-");
	AddRecordMhs(AllocateRecordMhs(CharToString("13508004"), CharToString("Ecky"), MakeTanggal(12,04,1990), CharToString("Jakarta")), &T);
	AddRecordMhs(AllocateRecordMhs(CharToString("13508020"), CharToString("Ghufron"), MakeTanggal(19,05,1991), CharToString("Demak")), &T);
	AddRecordMhs(AllocateRecordMhs(CharToString("13208025"), CharToString("Nazila"), MakeTanggal(13,11,1990), CharToString("Solo")), &T);
	AddRecordMhs(AllocateRecordMhs(CharToString("13508001"), CharToString("Archie"), MakeTanggal(01,07,1990), CharToString("Bandung")), &T);
	PrintTabelMhs(T); puts("-");
	
	TabelMK M = CreateEmptyTabelMK();
	printf("Tabel Mata Kuliah\n");
	PrintTabelMK(M); puts("-");
	AddRecordMK(AllocateRecordMK(CharToString("IF2030"), CharToString("Algoritma dan Struktur Data"), 4, CharToString("Pemrogaman")), &M);
	AddRecordMK(AllocateRecordMK(CharToString("EL2091"), CharToString("Sistem Digital"), 3, CharToString("Elektronika")), &M);
	AddRecordMK(AllocateRecordMK(CharToString("IF2132"), CharToString("Basis Data"), 3, CharToString("Basisdata")), &M);
	AddRecordMK(AllocateRecordMK(CharToString("KU1071"), CharToString("Pengantar Teknologi Informasi A"), 2, CharToString("Pemrogaman")), &M);
	PrintTabelMK(M); puts("-");
	
	ThnAkademik thn;
	thn = CreateThnAkademik(2009,2010);
	TabelPMK P = CreateEmptyTabelPMK();
	printf("Tabel Pengambilan Mata Kuliah\n");
	PrintTabelPMK(P); puts("-");
	AddRecordPMK(AllocateRecordPMK(SearchRecordMhsByNIM(CharToString("13508004"),&T), SearchRecordMKByKode(CharToString("IF2030"),&M),3,thn,'A'), &P);
	AddRecordPMK(AllocateRecordPMK(SearchRecordMhsByNIM(CharToString("13508004"),&T), SearchRecordMKByKode(CharToString("KU1071"),&M),1,CreateThnAkademik(2008,2009),'A'), &P);
	AddRecordPMK(AllocateRecordPMK(SearchRecordMhsByNIM(CharToString("13508020"),&T), SearchRecordMKByKode(CharToString("IF2030"),&M),3,thn,'A'), &P);
	AddRecordPMK(AllocateRecordPMK(SearchRecordMhsByNIM(CharToString("13508020"),&T), SearchRecordMKByKode(CharToString("EL2091"),&M),3,thn,'A'), &P);
	AddRecordPMK(AllocateRecordPMK(SearchRecordMhsByNIM(CharToString("13208025"),&T), SearchRecordMKByKode(CharToString("KU1071"),&M),1,CreateThnAkademik(2008,2009),'A'), &P);
	AddRecordPMK(AllocateRecordPMK(SearchRecordMhsByNIM(CharToString("13508001"),&T), SearchRecordMKByKode(CharToString("IF2132"),&M),4,thn,'A'), &P);
	PrintTabelPMK(P); puts("-");
	
	bool querytrue = true;
	while(querytrue) {
		printf("Query : "); ReadArguments(NULL);
		AddressPMK PMK;
		TRAVERSETOEND2(PMK,FIRST(P)) {
			if(!querytrue) break;
			if(EvaluateQueryTabelPMK(PMK,CReader,&querytrue)) { PrintRecordPMK(PMK,true,true,true,true,true); puts(""); }
		}	
	}
	
	DestroyRecordPMK(SearchRecordPMKByKey(SearchRecordMhsByNIM(CharToString("13508001"),&T),SearchRecordMKByKode(CharToString("IF2132"),&M),4,thn,&P), &P);
	if(SearchRecordPMKByKey(SearchRecordMhsByNIM(CharToString("13508020"),&T),SearchRecordMKByKode(CharToString("IF2030"),&M),3,thn,&P)!=NULL) puts("ADA!"); else puts("GA ADA!");
	PrintTabelPMK(P); puts("-");
	printf("size first = %d", GetRecordPMKSize(FIRST(P)));
	printf("\n");
	printf("Menghapus isi tabel T\n");
	DestroyTabelPMK(&P);
	PrintTabelPMK(P); puts("-");
	
	return 0;
}
